/**
 * 
 */
package com.tomagency.cyberlab.server.request;

import com.google.web.bindery.requestfactory.shared.ServiceLocator;
import com.tomagency.cyberlab.server.config.ConfigProviderFactory;

/**
 * @author gfr
 *
 */

public class CyberlabServiceLocator implements ServiceLocator {

	/* (non-Javadoc)
	 * @see com.google.gwt.requestfactory.shared.ServiceLocator#getInstance(java.lang.Class)
	 */
	@Override
	public Object getInstance(Class<?> clazz) {
//		System.out.println("BelegServiceLocator getInstance Klasse: "+clazz.getName());
		ConfigProviderFactory.getLoggingUtil().getLogger(this.getClass()).info("CyberlabServiceLocator getInstance Klasse: "+clazz.getName());
		//Anwendung von GUICE wäre hier besser
		Object instance= ConfigProviderFactory.getInjector().getInstance(clazz);
//		if (clazz.getName().equalsIgnoreCase(BelegRequestService.class.getName()))
//			return new BelegRequestServiceImpl();
//		else if (clazz.getName().equalsIgnoreCase(KontaktRequestService.class.getName()))
//			 return new KontaktRequestServiceImpl();
		if (instance!=null)
			return instance;
		
		else{
			
			ConfigProviderFactory.getLoggingUtil().getLogger(this.getClass()).info("CyberlabServiceLocator keine Impl vorhanden: "+clazz.getName());
			try {
				return clazz.newInstance();
			} catch (Exception e) {
				// TODO Auto-generated catch block  
				ConfigProviderFactory.getLoggingUtil().getLogger(this.getClass()).error("CyberlabServiceLocator getInstance Klasse: "+clazz.getName(),e);
				return null;
			}
		}
	}
}
